import axios from '@u/request'

const fetchCates = (params = {}) => {
  return axios.get('/shop/goods/category/all', {params})
}
// 请求首页轮播
const fetchHomeBanner = (params = {}) => {
  return axios.get('/banner/list', {params})
}
// 请求商品列表
const fetchItems = (params = {}) => (
  axios.post('/shop/goods/list/v2', params)
)
// 请求商品详情
const fetchItemDetail = (params = {}) => axios.get('/shop/goods/detail', {params})
// 用户注册接口 /user/username/register
const userReg = (params = {}) => axios.post('/user/username/register', params)
// 用户登录接口 /user/username/register
const userLog = (params = {}) => axios.post('/user/username/login', params)

// 以下是购物车相关接口
// 加入购物车
const addItemToCart = (params = {}) => axios.post('/shopping-cart/add', params)
// 获取购物车数据  /shopping-cart/info
const fetchCartInfo = (params = {}) => axios.get('/shopping-cart/info', {params})
// 修改购物车商品购买数量 /shopping-cart/modifyNumber
const modifyCartItemNum = (params = {}) => axios.post('/shopping-cart/modifyNumber', params)
// 购物车中删除某个商品 /shopping-cart/remove
const removeCartItem = (params = {}) => axios.post('/shopping-cart/remove', params)
// 修改购物车商品选中状态 /shopping-cart/select
const modifyCartSelected = (params = {}) => axios.post('/shopping-cart/select', params)
export {
  fetchCates,
  fetchHomeBanner,
  fetchItems,
  fetchItemDetail,
  userReg,
  userLog,
  addItemToCart,
  fetchCartInfo,
  modifyCartItemNum,
  removeCartItem,
  modifyCartSelected
}